getColor

open fun getColor(@NonNull context: Context, @ColorRes id: Int): Int(source)

Returns a color associated with a particular resource ID

Starting in M, the returned color will be styled for the specified Context's theme.

Return

A single color value in the form 0xAARRGGBB.

Parameters

context

context to use for getting the color.

id

The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.

Throws

if the given ID does not exist.